package org.lc.service.system.client.error;

import feign.Response;
import feign.codec.ErrorDecoder;
import org.lc.platform.base.exception.SystemException;

public class FeignErrorDecoder implements ErrorDecoder {

    private final ErrorDecoder defaultErrorDecoder = new Default();

    @Override
    public Exception decode(String methodKey, Response response) {
        // 获取Feign返回的原始异常信息
        int status = response.status();
        if (status == 503) {
            return new SystemException("微服务：《" + methodKey + "》 不可达");
        }
        return defaultErrorDecoder.decode(methodKey, response);
    }

}
